package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.RegionQueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {
    @Autowired
    private RegionMapper regionMapper;

    public List<Region> listByState(Integer state) {
        return regionMapper.selectByState(state);
    }



    public List<Region> list() {
        return regionMapper.selectAll();
    }

    public List<Region> queryMenus(RegionQueryObject qo) {
        if (qo.getParentId() == null) {
            return regionMapper.selectRootMenus();
        }
        return regionMapper.selectMenus(qo);
    }

    public void saveOrUpdate(Region entity) {
        if (entity.getId() == null) {
            regionMapper.insert(entity);
        } else {
            regionMapper.updateByPrimaryKey(entity);
        }
    }

    @Override
    public List<Region> listTicket(QueryObject qo) {

        return regionMapper.listTicket(qo);
    }
}
